package com.shop.cloud.common.jpush;

import java.util.Collection;

import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.audience.AudienceTarget;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;

public class AppPushUtil {

	public static PushPayload buildPushObject_android_ios_audienceNotification(String Tokens, String Contents) {
		return PushPayload
				.newBuilder()
				.setPlatform(Platform.android_ios())
				.setAudience(Audience.newBuilder().addAudienceTarget(AudienceTarget.alias(Tokens)).build())
				.setNotification(
						Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().setAlert(Contents).setSound("happy").build())
								.addPlatformNotification(AndroidNotification.newBuilder().setAlert(Contents).build()).build()).build();

	}

	public static PushPayload buildPushObject_android_and_ios(String Token, String Contents) {
		return PushPayload.newBuilder().setPlatform(Platform.android_ios()).setAudience(Audience.alias(Token)).setNotification(Notification.newBuilder().setAlert(Contents).build()).build();
	}

	public static PushPayload buildPushObject_android_and_ios(Collection<String> Tokens, String Contents) {
		return PushPayload.newBuilder().setPlatform(Platform.android_ios()).setAudience(Audience.alias(Tokens)).setNotification(Notification.newBuilder().setAlert(Contents).build()).build();
	}

	public static PushPayload buildPushObject_all_all_alert(String Token, String Contents) {
		return PushPayload.newBuilder().setPlatform(Platform.android_ios()).setAudience(Audience.newBuilder().addAudienceTarget(AudienceTarget.alias(Token)).build())
				.setMessage(Message.newBuilder().setMsgContent(Contents).build()).build();
	}

	public static PushPayload buildPushObject_android_ios_audienceNotification(Collection<String> Tokens, String Contents) {
		return PushPayload
				.newBuilder()
				.setPlatform(Platform.android_ios())
				.setAudience(Audience.newBuilder().addAudienceTarget(AudienceTarget.alias(Tokens)).build())
				.setNotification(
						Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().setAlert(Contents).setSound("happy").build())
								.addPlatformNotification(AndroidNotification.newBuilder().setAlert(Contents).build()).build()).build();

	}

	public static PushPayload buildPushObject_android_alias_alert(String TITLE, String ALERT, String Token) {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(Token)).setNotification(Notification.android(ALERT, TITLE, null)).build();
	}

	public static PushPayload buildPushObject_ios_alias_alert(String TITLE, String ALERT, String Token) {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(Token)).setNotification(Notification.android(ALERT, TITLE, null)).build();
	}

	public static PushPayload buildPushObject_all_alias_alert(String ALERT, String Token) {
		return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(Token)).setNotification(Notification.alert(ALERT)).build();
	}

	public static PushPayload buildPushObject_android_tag_alertWithTitle(String ALERT, String TITLE) {
		return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.tag("tag1")).setNotification(Notification.android(ALERT, TITLE, null)).build();
	}

	public static PushPayload buildPushObject_android_and_ios() {
		return PushPayload
				.newBuilder()
				.setPlatform(Platform.android_ios())
				.setAudience(Audience.tag("tag1"))
				.setNotification(
						Notification.newBuilder().setAlert("alert content").addPlatformNotification(AndroidNotification.newBuilder().setTitle("Android Title").build())
								.addPlatformNotification(IosNotification.newBuilder().incrBadge(1).addExtra("extra_key", "extra_value").build()).build()).build();
	}

	public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage(String ALERT, String MSG_CONTENT) {
		return PushPayload
				.newBuilder()
				.setPlatform(Platform.ios())
				.setAudience(Audience.tag_and("tag1", "tag_all"))
				.setNotification(
						Notification.newBuilder().addPlatformNotification(IosNotification.newBuilder().setAlert(ALERT).setBadge(5).setSound("happy").addExtra("from", "JPush").build()).build())
				.setMessage(Message.content(MSG_CONTENT)).setOptions(Options.newBuilder().setApnsProduction(true).build()).build();
	}

	public static PushPayload buildPushObject_ios_audienceMore_messageWithExtras(String MSG_CONTENT) {
		return PushPayload.newBuilder().setPlatform(Platform.android_ios())
				.setAudience(Audience.newBuilder().addAudienceTarget(AudienceTarget.tag("tag1", "tag2")).addAudienceTarget(AudienceTarget.alias("alias1", "alias2")).build())
				.setMessage(Message.newBuilder().setMsgContent(MSG_CONTENT).addExtra("from", "JPush").build()).build();
	}

}
